﻿ #define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
	vector<string> ﬁndWords(vector<string>& words) {
		vector<string> vret;
		string lineString[3] = { "qwertyuiopQWERTYUIOP", "asdfghjklASDFGHJKL", "zxcvbnmZXCVBNM" };
		// 将三行内容放到unordered_set中
		unordered_set<char> sets[3];
		for (int i = 0; i < 3; ++i)
		{
			for (auto ch : lineString[i])
				sets[i].insert(ch);
		}
		// 逐个取到每个单词
		for (auto word : words)
		{
			bool ﬂags[3] = { false, false, false };
			// 检测该单词中的每个字符是否在同一行出现了
			for (auto ch : word)
			{
				for (int i = 0; i < 3; ++i)
				{
					if (sets[i].ﬁnd(ch) != sets[i].end())
					{
						ﬂags[i] = true;
					}
				}
			}
			int count = 0;
			for (bool ﬂag : ﬂags)
			{
				if (ﬂag)
					count++;
			}
			if (count == 1)
			{
				vret.push_back(word);
			}
		}
		return vret;
	}
};